/*
 * psUart.h
 *
 *  Created on: May 27, 2021
 *      Author: tau
 */

#ifndef DRV_PSUART_H_
#define DRV_PSUART_H_

#include <string>
#include <iostream>
#include <stdexcept>
#include <pthread.h>
#include <mutex>

#define __HEAD_TAIL_MAX_LEN 16
#define __MSG_SEND_MAX_LEN 256
#define __MSG_RXED_MAX_LEN 256

using namespace std;

typedef struct{
	int fd;
	string name;
	char txHead[__HEAD_TAIL_MAX_LEN];
	char txTail[__HEAD_TAIL_MAX_LEN];
	char rxHead[__HEAD_TAIL_MAX_LEN];
	char rxTail[__HEAD_TAIL_MAX_LEN];
	void (*func)(char*);
}psUartBase_t;

class psUart {

private:
	int __fd;
	mutex __m;
	psUartBase_t psUB;
	pthread_t threadID;
	static void* __uartUpdate(void* args );

public:
	psUart(string name ,int buadRate,char* txHead,char* txTail,char* rxHead,char* rxTail,void (*callback)(char*));
	virtual ~psUart();
	int sendData(char* data);
};

#endif /* DRV_PSUART_H_ */
